package com.dgut.leave.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.*;
import com.fasterxml.jackson.annotation.JsonFormat;

@Entity
@Table(name = "t_leave")
public class Leave implements Serializable {
	private static final long serialVersionUID = 1L;

	// 业务数据字段
	private Long id;
	private String userId;// 用户登录的用户名
	@DateTimeFormat(pattern = "yyyy/MM/dd HH:mm:ss")
	private Date beginDate;// 请假开始时间
	@DateTimeFormat(pattern = "yyyy/MM/dd HH:mm:ss")
	private Date endDate;// 请假结束时间
	@DateTimeFormat(pattern = "yyyy/MM/dd HH:mm:ss")
	private Date realityStartTime;// 实际开始时间
	@DateTimeFormat(pattern = "yyyy/MM/dd HH:mm:ss")
	private Date realityEndTime;// 实际结束时间
	@DateTimeFormat(pattern = "yyyy/MM/dd HH:mm:ss")
	private Date applyTime;// 申请时间
	private String leaveType;// 请假类型
	private String reason;// 申请理由
	private String status;// 处理状态

	// 工作流程数据字段
	// 流程实例Id：用于关联下列临时数据
	private String processInstanceId; // 没有启动流程之前为""
	// -- 临时属性 @Transient 不会被保存到当前实体的OA_LEAVE表，用于临时存储流程数据，目的是让工作流数据与业务数据结合--//
	private Task task;// 流程任务
	private Map<String, Object> variables;// 流程变量
	// 运行中的流程实例
	private ProcessInstance processInstance;
	// 历史的流程实例
	private HistoricProcessInstance historicProcessInstance;
	// 流程定义
	private ProcessDefinition processDefinition;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}

	@JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
	public Date getBeginDate() {
		return beginDate;
	}

	@JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
	public Date getEndDate() {
		return endDate;
	}

	public String getReason() {
		return reason;
	}

	public String getStatus() {
		return status;
	}

	public String getUserId() {
		return userId;
	}

	public String getLeaveType() {
		return leaveType;
	}

	@JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
	public Date getRealityStartTime() {
		return realityStartTime;
	}

	@JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
	public Date getRealityEndTime() {
		return realityEndTime;
	}

	@JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
	public Date getApplyTime() {
		return applyTime;
	}

	public String getProcessInstanceId() {
		return processInstanceId;
	}

	@Transient // 临时属性
	public Task getTask() {
		return task;
	}

	@Transient
	public Map<String, Object> getVariables() {
		return variables;
	}

	@Transient
	public ProcessInstance getProcessInstance() {
		return processInstance;
	}

	@Transient
	public HistoricProcessInstance getHistoricProcessInstance() {
		return historicProcessInstance;
	}

	@Transient
	public ProcessDefinition getProcessDefinition() {
		return processDefinition;
	}

	public void setRealityStartTime(Date realityStartTime) {
		this.realityStartTime = realityStartTime;
	}

	public void setRealityEndTime(Date realityEndTime) {
		this.realityEndTime = realityEndTime;
	}

	public void setApplyTime(Date applyTime) {
		this.applyTime = applyTime;
	}

	public void setProcessInstanceId(String processInstanceId) {
		this.processInstanceId = processInstanceId;
	}

	public void setTask(Task task) {
		this.task = task;
	}

	public void setVariables(Map<String, Object> variables) {
		this.variables = variables;
	}

	public void setProcessInstance(ProcessInstance processInstance) {
		this.processInstance = processInstance;
	}

	public void setHistoricProcessInstance(HistoricProcessInstance historicProcessInstance) {
		this.historicProcessInstance = historicProcessInstance;
	}

	public void setProcessDefinition(ProcessDefinition processDefinition) {
		this.processDefinition = processDefinition;
	}

	public void setLeaveType(String leaveType) {
		this.leaveType = leaveType;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public void setReason(String reason) {
		this.reason = reason;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@Override
	public String toString() {
		return "Leave [id=" + id + ", userId=" + userId + ", beginDate=" + beginDate + ", endDate=" + endDate
				+ ", leaveType=" + leaveType + ", reason=" + reason + ", status=" + status + "]";
	}

}
